/**
 * 
 */
package com.gragra.frameStatistics.tests;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.StringReader;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.Corpus;
import com.gragra.frameStatistics.StatisticsGenerator;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.CaseLevelAssigningSegmenter;
import com.gragra.sequentiaDataGenerator.PunctuationSplitOffSegmenter;
import com.gragra.util.StringToInt;
/**
 * @author Christoph Teichmann
 * created Mar 28, 2013 2:57:44 PM
 * @version 0.1
 */
public class TestStatisticsGenerator
{
	/**
	 * 
	 */
	private WordAndTagHolder wth;
	/**
	 * 
	 */
	private StatisticsGenerator sg;
	/**
	 *
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		StringReader sr = new StringReader("This|0|WordTypeLevel|Noun IS|NONE something.|0|ContextTagLevel|10 \n this|Pronoun too.|NONE|WordTypeLevel|Function");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new CaseLevelAssigningSegmenter(new PunctuationSplitOffSegmenter("NONE")));
		Corpus<WordAndTagHolder> corp = bg.createCorpus(br);
		sg = new StatisticsGenerator(corp, 3, 1, 1);
		wth = corp.getEntry(0);
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getWordCount(int)}.
	 */
	@Test
	public final void testGetWordCount()
	{
		assertEquals(2,sg.getWordCount(StringToInt.ensure("this")),0.0001);
		assertEquals(0,sg.getWordCount(StringToInt.ensure("This")),0.0001);
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getAllWords()}.
	 */
	@Test
	public final void testGetAllWords()
	{
		assertEquals(sg.getAllWords().size(),5);
		assertTrue(sg.getAllWords().contains(StringToInt.ensure("this")));
		assertTrue(sg.getAllWords().contains(StringToInt.ensure("is")));
		assertTrue(sg.getAllWords().contains(StringToInt.ensure("something")));
		assertTrue(sg.getAllWords().contains(StringToInt.ensure("too")));
		assertTrue(sg.getAllWords().contains(StringToInt.ensure(".")));
		assertEquals(sg.getAllWords(),sg.getAllWords());
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#hasFrameFor(int)}.
	 */
	@Test
	public final void testHasFrameFor()
	{
		sg.fillMappedSequence(wth);
		assertTrue(sg.hasFrameFor(1,wth));
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#fillFrameExternal(int)}.
	 */
	@Test
	public final void testFillFrameExternal()
	{
		sg.fillMappedSequence(wth);
		sg.fillFrameExternal(0);
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getAllFrames()}.
	 */
	@Test
	public final void testGetAllFrames()
	{assertEquals(sg.getAllFrames().size(),7);}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getFrameFrequency(int)}.
	 */
	@Test
	public final void testGetFrameFrequency()
	{
		assertEquals(sg.getFrameFrequency(0),1.0,0.0001);
		assertEquals(sg.getFrameFrequency(7),0.0,0.0001);
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getCoOccurringWords(int)}.
	 */
	@Test
	public final void testGetCoOccurringWords()
	{
		assertEquals(sg.getCoOccurringWords(0).size(),1);
		assertEquals(sg.getCoOccurringWords(0).iterator().nextInt(), StringToInt.ensure("this"));
	}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#getWordFrameFrequency(int, int)}.
	 */
	@Test
	public final void testGetWordFrameFrequency()
	{assertEquals(sg.getWordFrameFrequency(0, StringToInt.ensure("is")),0.0,0.0001);}
	/**
	 * Test method for {@link com.gragra.frameStatistics.StatisticsGenerator#frameToString(int)}.
	 */
	@Test
	public final void testFrameToString()
	{assertEquals("< this _ something >",sg.frameToString(1));}
}